//
//  BankAccountsTableViewCell.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/8/21.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "BankAccountsTableViewCell.h"
#import "BankDetailsViewController.h"
#import "AddAddressViewController.h"

@interface BankAccountsTableViewCell ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLeadingLayout;
@property (weak, nonatomic) IBOutlet UIButton *gouxuan;

@end

@implementation BankAccountsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)gouxuanAction:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    
    if (self.bankAccount) {
        self.bankAccount.select = sender.selected;
    }else {
        self.cryptoAddress.select = sender.selected;
    }
}

- (void)setEdit:(BOOL)edit {
    _edit = edit;
    self.titleLeadingLayout.constant = edit ? 42 : 17;
    self.gouxuan.hidden = !edit;
}

- (void)setBankAccount:(BankAccountListEntity *)bankAccount {
    if (bankAccount != _bankAccount) {
        _bankAccount = bankAccount;
        
        self.bankName.text = bankAccount.datas.bank_name;
        self.pending.text = [bankAccount.verification_status uppercaseString];
        self.bankUser.text = [NSString stringWithFormat:@"%@    %@", bankAccount.datas.account_name, bankAccount.datas.account_number];
        
        self.gouxuan.selected = bankAccount.select;
    }
}

- (void)setCryptoAddress:(CryptoAddressEntity *)cryptoAddress {
    if (cryptoAddress != _cryptoAddress) {
        _cryptoAddress = cryptoAddress;
        
        self.bankName.text = [NSString stringWithFormat:@"%@-%@", cryptoAddress.currencies_id.name, cryptoAddress.currencies_id.token_name] ;
        self.pending.text = [cryptoAddress.address_status uppercaseString];;
        self.bankUser.text = cryptoAddress.wallet_address;
        
        self.gouxuan.selected = cryptoAddress.select;
        
        self.detailBtn.hidden = [cryptoAddress.address_status isEqualToString:@"verified"];
    }
}


- (IBAction)goDetail:(id)sender {
    if (self.bankAccount) {
        BankDetailsViewController *vc = [[UIStoryboard storyboardWithName:@"User" bundle:nil]instantiateViewControllerWithIdentifier:@"BankDetailsViewController"];
        vc.entity = self.bankAccount;
        [self.viewController.navigationController pushViewController:vc animated:YES];
    }else {
        AddAddressViewController *vc = [[UIStoryboard storyboardWithName:@"User" bundle:nil]instantiateViewControllerWithIdentifier:@"AddAddressViewController"];
        vc.cryptoAddress = self.cryptoAddress;
        [self.viewController.navigationController pushViewController:vc animated:YES];
    }
}

@end
